package com.baor.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baor.dao.AdjustDao;
import com.baor.dao.ApprovalDao;
import com.baor.dao.ChangeDao;
import com.baor.domain.AdjustVo;
import com.baor.domain.LeaveVo;
import com.baor.service.AdjustService;
import com.baor.service.ApprovalService;
import com.baor.service.ChangeService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Service
public class ApprovalServiceImpl implements ApprovalService {

    @Autowired
    private ApprovalDao approvalDao;

    @Autowired
    private AdjustService adjustService;

    @Autowired
    private ChangeService changeService;


    @Override
    public AjaxResult<?> empApprovalList(Map<String, Object> map) {
        map.put("pageIndex", (int)map.get("pageSize") * ((int)(map.get("pageIndex")) - 1));
        map.put("pageSize", map.get("pageSize"));
        Map<String,Object> res = new HashMap<>();
        res.put("approvalList",this.approvalDao.empApprovalList(map));
        res.put("pageCount",this.approvalDao.empPageCount(map));
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> empApproval(Map<String,Object> map) {
        return AjaxResult.success(this.approvalDao.empApproval(map));
    }

    @Override
    public AjaxResult<?> adjustApprovalList(Map<String, Object> map) {
        map.put("pageIndex", (int)map.get("pageSize") * ((int)(map.get("pageIndex")) - 1));
        map.put("pageSize", map.get("pageSize"));
        Map<String,Object> res = new HashMap<>();
        res.put("approvalList",this.approvalDao.adjustApprovalList(map));
        res.put("pageCount",this.approvalDao.adjustPageCount(map));
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> adjustApproval(Map<String, Object> map) {
        int code = adjustService.updateData(approvalDao.selectAdjust(map)).getCode();
        if(code == 200){
            approvalDao.adjustApproval(map);
            return AjaxResult.success("审批成功");
        }else{
            return AjaxResult.error("审批失败");
        }
    }

    @Override
    public AjaxResult<?> changeApprovalList(Map<String, Object> map) {
        map.put("pageIndex", (int)map.get("pageSize") * ((int)(map.get("pageIndex")) - 1));
        map.put("pageSize", map.get("pageSize"));
        Map<String,Object> res = new HashMap<>();
        res.put("approvalList",this.approvalDao.changeApprovalList(map));
        res.put("pageCount",this.approvalDao.changePageCount(map));
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> changeApproval(Map<String, Object> map) {
        int code = changeService.updateData(approvalDao.selectChange(map)).getCode();
        if(code == 200){
            approvalDao.changeApproval(map);
            return AjaxResult.success("审批成功");
        }else{
            return AjaxResult.error("审批失败");
        }
    }
}
